<template>
  <div class="app-container">
    <el-card class="box-card operate-container">
      <div
        slot="header"
        class="clearfix"
      >
        <span>文件筛选</span>
      </div>
      <div class="">
        <!-- 打开文件 -->
        <div class="openFile">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-upload
                ref="upload"
                class="upload-demo"
                action="https://"
                :on-remove="handleRemove"
                :file-list="fileList"
                :auto-upload="false"
              >
                <el-button
                  slot="trigger"
                  size="medium"
                  type="primary"
                >
                  打开文件
                </el-button>
                <!-- <el-button
                  style="margin-left: 10px"
                  size="medium"
                  type="success"
                  @click="submitUpload"
                  >上传到服务器</el-button
                > -->
                <div
                  slot="tip"
                  class="el-upload__tip"
                >
                  上传bat文件，且不超过10M
                </div>
              </el-upload>
            </el-col>
            <el-col :span="18">
              <el-button
                type="success"
                size="medium "
              >
                下载
              </el-button>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-input
                v-model="input"
                placeholder="bat文件路径"
              />
            </el-col>
            <el-col :span="12">
              <el-button
                type="success"
                size="medium "
              >
                进度
              </el-button>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-input
                v-model="input"
                placeholder="swi文件路径"
              />
            </el-col>
            <el-col :span="12">
              <el-button
                type="success"
                size="medium "
              >
                进度
              </el-button>
            </el-col>
          </el-row>
        </div>
        <!-- 查询 -->
        <div class="query">
          <el-form
            ref="form"
            :model="listQuery"
            label-width="120px"
          >
            <el-row :gutter="20">
              <el-col :span="4">
                <el-form-item label="地市">
                  <el-select
                    v-model="listQuery.busPrefix"
                    placeholder="请选择地市"
                    clearable
                  >
                    <el-option
                      v-for="item in cityOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="时间选择">
                  <el-date-picker
                    v-model="value1"
                    type="date"
                    placeholder="选择日期"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="slm/clm">
                  <el-radio-group v-model="listQuery.slmclm">
                    <el-radio :label="0">
                      slm
                    </el-radio>
                    <el-radio :label="1">
                      clm
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
        
              <el-col :span="6">
                <el-form-item label="模型">
                  <el-radio-group v-model="listQuery.model">
                    <el-radio :label="0">
                      统一模型
                    </el-radio>
                    <el-radio :label="1">
                      单站模型
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item>
                  <el-button type="success">
                    重置
                  </el-button>
                  <el-button
                    type="primary"
                    @click="onSubmit"
                  >
                    模糊查询
                  </el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: null,
      listLoading: false,
      file: {
        name: "",
      },
      listQuery: {
        slmclm: "", //slmclm
        model: "", // 统一模型/单站模型
      },
      cityOptions: [
        {
          value: "0",
          label: "省调",
        },
        {
          value: "1",
          label: "地调",
        },
    
      ],
     
      fileList: [],
      fileContent: "", // .bat文件内容
      data: [], // 数据行信息
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    handleRemove() {
      console.log("000");
    },
    handleUpload(event) {
      const file = event.target.files[0];

      if (file === undefined || !file.type.includes("text/plain")) {
        alert("只能上传txt类型的文件");
        return;
      }

      this.readBatFile(file);
    },

    readBatFile(file) {
      const reader = new FileReader();

      reader.onload = () => {
        this.parseBatFile(reader.result);
      };

      reader.readAsText(file);
    },

    parseBatFile(content) {
      // 根据具体情况编写正则表达式或其他处理方法来提取数据
      // 此处仅作示例，假设每行数据由空格分隔
      const lines = content.split("\n");
      let headersFound = false;

      for (let i = 0; i < lines.length; i++) {
        const line = lines[i].trim();

        if (!headersFound) {
          // 第一行为列头信息
          this.headers = line.split(" ").filter((value) => value !== "");
          headersFound = true;
        } else {
          // 从第二行开始为数据行信息
          this.data.push(line.split(" "));
        }
      }

      this.dataLoaded = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.mainBox {
  width: 100%;
  height: 100%;
  background-color: aqua;

  .box-card {
    width: 96%;
  }
}
.query {
  margin: 50px 0;
}
</style>
